package com.iuie.ns.frame.web.dataset.description;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.iuie.ns.frame.web.dataset.vo.ColsVO;

/**
 * DataField属性描述
 * @author lj
 * @date 2016年12月15日14:21:43
 */
public class DataFieldDescription extends ColsVO{

	private String dataSetName;
	
	private Set<DataFieldDescription> others = new HashSet<DataFieldDescription>();
	
	public DataFieldDescription(){
		this("");
	}
	
	public DataFieldDescription(String datasetName) {
		this.dataSetName = datasetName;
	}
	
	public DataFieldDescription(ColsVO cols){
		super(cols);
	}
	
	public String getDataSetName() {
		return dataSetName;
	}

	public void setDataSetName(String dataSetName) {
		this.dataSetName = dataSetName;
	}

	public Set<DataFieldDescription> getOthers() {
		return others;
	}

	public void setOthers(Set<DataFieldDescription> others) {
		this.others = others;
	}

	public void addOther(DataFieldDescription description) {
		this.others.add(description);
	}

	protected ColsVO toCols(String name) {
		/**
		 * if name == "" then
		 * 		return this.cols
		 * 	for other in others
		 * 		if(other.dataSetName == name)
		 * 			return other.cols
		 * return this.cols
		 */
		// 1. 首先看是不是要找this的值
		if("".equals(name)){
			ColsVO cols = new ColsVO(this);
			return cols;
		} 
		// 2. 看看others里面有没有
		Iterator<DataFieldDescription> it = this.others.iterator();
		while (it.hasNext()) {
			DataFieldDescription description = it.next();
			if (description.getDataSetName().equals(name)) {
				ColsVO cols = new ColsVO(description);
				return cols;
			}
		}
		// 3. 都没有，那还是用this的值
		ColsVO cols = new ColsVO(this);
		return cols;
	}

}
